package login2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/index2")
public class indexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=utf8");
        //获取会话信息
        HttpSession session = req.getSession(false);
        if(session == null) {
            //说明还没有登录
            resp.sendRedirect("login.html");
            return;
        }
        //成功进入主页
        String username = (String)session.getAttribute("username");
        int loginCount = (int)session.getAttribute("loginCount");
        resp.getWriter().write("欢迎回来:" + username + "<br>"
        + "您已登陆" + loginCount + "次~");
    }
}
